//例一
/*package main

import (
	"fmt"
	"time"
)

var chanInt = make(chan int, 0)
var chanStr = make(chan string)

func main() {

	go func() {
		chanInt <- 100
		chanStr <- "hello"
		defer close(chanInt)
		defer close(chanStr)
	}()

	for {
		select {
		case r := <-chanInt:
			fmt.Printf("chanInt: %v\n", r)
		case r := <-chanStr:
			fmt.Printf("chanStr: %v\n", r)
		default:
			fmt.Println("default...")
			break
		}
		time.Sleep(time.Second)
	}

}*/

//golang for select 循环跳出
//分析：
//使用break lable 和 goto lable 都能跳出for循环；不同之处在于：break标签只能用于for循环，且标签位于for循环前面，goto是指跳转到指定标签处

//1.使用break：
/*package main

import (
	"fmt"
	"time"
)

func main()  {
	SelectTest()
}
func SelectTest() {
	i := 0
Loop:
	for {
		select {
		case <-time.After(time.Second * time.Duration(2)):
			i++
			if i == 5 {
				fmt.Println("跳出for循环")
				break Loop
			}
		}
		fmt.Println("for循环内 i=", i)
	}

	fmt.Println("for循环外")
}*/

//golang for select 循环跳出
//2.使用goto：
/*package main

import (
	"fmt"
	"time"
)

func main()  {
	SelectTest()
}
func SelectTest() {
	i := 0
	for {
		select {
		case <-time.After(time.Second * time.Duration(2)):
			i++
			if i == 5 {
				fmt.Println("跳出for循环")
				goto Loop
			}
		}
		fmt.Println("for循环内 i=", i)
	}
Loop:
	fmt.Println("for循环外")
}*/